package com.caocaog.market.vo;

import com.caocaog.market.entity.ShopDelivery;
import com.caocaog.market.entity.ShopKilometerPrice;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

import javax.validation.Valid;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;

@Getter
@Setter
public class ShopDeliveryVO implements Serializable {

    private static final long serialVersionUID = 1L;

    @NotNull(message = "请传入绑定的店铺主键（shopId）")
    @ApiModelProperty(value = "主键")
    private String shopId;

    @NotNull(message = "起始公里不能为空")
    @DecimalMin(value = "0", message = "非法起始价格")
    @ApiModelProperty(value = "起始价格", required = true)
    private BigDecimal startPrice;

    @NotNull(message = "起始公里不能为空")
    @DecimalMin(value = "0", message = "非法起始公里")
    @ApiModelProperty(value = "起始公里", required = true)
    private BigDecimal startKilometer;

    @NotNull(message = "超出价格不能为空")
    @DecimalMin(value = "0", message = "非法超出价格")
    @ApiModelProperty(value = "超出价格", required = true)
    private BigDecimal exceedPrice;

    @NotNull(message = "超出公里不能为空")
    @DecimalMin(value = "0", message = "非法超出公里")
    @ApiModelProperty(value = "超出公里", required = true)
    private BigDecimal exceedKilometer;

    @Valid
    @ApiModelProperty(value = "区间")
    private List<ShopKilometerPrice> interval;

    @ApiModelProperty(hidden = true)
    public ShopDelivery toShopDelivery() {
        ShopDelivery shopDelivery = new ShopDelivery();
        shopDelivery.setShopId(this.shopId);
        shopDelivery.setStartPrice(this.startPrice);
        shopDelivery.setStartKilometer(this.startKilometer);
        shopDelivery.setExceedPrice(this.exceedPrice);
        shopDelivery.setExceedKilometer(this.exceedKilometer);
        return shopDelivery;
    }

    @ApiModelProperty(hidden = true)
    public void setShopDelivery(ShopDelivery shopDelivery) {
        this.shopId = shopDelivery.getShopId();
        this.startPrice = shopDelivery.getStartPrice();
        this.startKilometer = shopDelivery.getStartKilometer();
        this.exceedPrice = shopDelivery.getExceedPrice();
        this.exceedKilometer = shopDelivery.getExceedKilometer();
    }

}
